package l1j.opqlo.NewSystem;

import java.util.logging.Level;
import java.util.logging.Logger;

import l1j.opqlo.NewSystem.Extension.TreasureMaster;
import l1j.opqlo.Server.L1World.L1World;
import l1j.server.Thread.GeneralThreadPool;
import l1j.server.server.utils.Random;


public class XMas  {
	private static int XmasCount = 0 , BOSS_COUNT = 0;

	//X synchronized
	public static void addXmasCount(){
		if(BOSS_COUNT <=0){
			BOSS_COUNT = Random.nextInt(50)+100;
		}
		XmasCount++;
		System.out.println("XMAS_COUNT:"+XmasCount + " / "+ BOSS_COUNT);
		if(XmasCount >= BOSS_COUNT){
			XmasCount =0;
			BOSS_COUNT = Random.nextInt(50)+100;
			new XMast().start();
		}else{
			boolean broad = false;
			final int count = BOSS_COUNT-XmasCount;
			switch(count){
			case 50:
			case 20:
			case 15:
			case 10:
			case 5:
			case 4:
			case 3:
			case 2:
			case 1:
				broad = true;
				break;
			}
			if(broad){
				L1World.getInstance().broadcastServerMessage("距BOSS出現，還需擊殺馴鹿 ["+count+"]隻。");
			}
		}
	}
}


class XMast implements Runnable {

	private final static Logger _log = Logger.getLogger(XMast.class.getName());

	private static short[] _mapid = {
		604,
		605,
		606,
		607,
		6321,
		9901,
		9914,
		9915,
		9916,
		9918,
		9919,
		9920,
		9921,
		9922,
		9923,
		9991,
		9992,
		9993,
		9994,
		9995
	};

	private static String[] _mapName = {
		"水之領域",
		"火之領域",
		"風之領域",
		"地之領域",
		"羅馬競技場",
		"黑暗洞穴",
		"傳說島嶼",
		"狼族墓穴",
		"失落之境",
		"[九階]武防區",
		"[八階]武防區",
		"[七階]武防特區",
		"[六階]武防特區",
		"死幽谷",
		"廢棄礦場",
		"[一階]武防區",
		"[二階]武防區",
		"[三階]武防區",
		"[四階]武防區",
		"[五階]武防區"

	};


	public void start(){
		GeneralThreadPool.getInstance().schedule(this, 500);
	}

	@Override
	public void run() {
		final int list = Random.nextInt(_mapid.length);
		try{
			TreasureMaster.getInstance().spawn(0, 2000265, 1, 0,0, _mapid[list], 1, 0, false);
			L1World.getInstance().broadcastServerMessage("\\aG[BOSS]聖誕魔人 出現在 ["+_mapName[list]+"] 。");
		}catch(Exception e){
			_log.log(Level.SEVERE ,  e.getLocalizedMessage() , e);
		}finally{
			_log.info("[BOSS]聖誕魔人 出現在 ["+_mapName[list]+"] 。");
		}
	}
}
